using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using DTO;

using System.Data;

namespace Business
{
    public class HoaDonService
    {




		//////////////////////////////////////////////////////////

 		                                                         

		//            Enter code your here                      //

		                                                         

		//////////////////////////////////////////////////////////

       static public DataTable ConvertListHoaDonDTOToDataTable( List<HoaDonDTO> lst)
       {
               DataTable dt = new DataTable();
           dt.Columns.Add( "MaHoaDon");
           dt.Columns.Add( "TriGia");
           dt.Columns.Add( "MaKhachHang");
           for( int i = 0; i < lst.Count; i ++)
           {
               dt.Rows.Add(
                       lst[i].MaHoaDon,      
                       lst[i].TriGia,      
                       lst[i].MaKhachHang      
                   );
           }
               return dt;
       }
        static public int GetIdentity()
        {
            Data.HoaDonRepository repo = new HoaDonRepository();
            return repo.GetIdentity();
        }

        static public int Count()
        {
            return HoaDonRepository.Count();
        }
        public static bool Them(HoaDonDTO objDTO)
        {
                HoaDonRepository repo = new HoaDonRepository();
                return repo.Them(objDTO);
        }

        public static bool Xoa(int MaHoaDon, bool XoaKhoaNgoai=false)
        {
              HoaDonRepository Repo = new HoaDonRepository();
              return Repo.Xoa(MaHoaDon,XoaKhoaNgoai);
        }

        public static void CapNhat(HoaDonDTO objDTO)
        {
            try
            {
                HoaDonRepository Repo = new HoaDonRepository();
                Repo.CapNhat(objDTO);
            }
            catch (System.Exception )
            {
            }
        }

        public static List<HoaDonDTO> LayDanhSach()
        {
            List<HoaDonDTO> lst = new List<HoaDonDTO>();
            try
            {
                HoaDonRepository obj = new HoaDonRepository();
                lst = obj.LayDanhSach();
            }
            catch (System.Exception )
            {
            }
            return lst;
        }

        static public List<HoaDonDTO> LayDanhSach(int Start, int Record)
        {
             Data.HoaDonRepository repo = new HoaDonRepository();
            return repo.LayDanhSach(Start, Record);
        }

        public static HoaDonDTO LayTheoMa(int MaHoaDon)
        {
            HoaDonDTO objDTO = new HoaDonDTO();
            try
            {
                HoaDonRepository Repo = new HoaDonRepository();
                objDTO = Repo.LayTheoMa(MaHoaDon);
            }
            catch (System.Exception )
            {
            }
            return objDTO;
        }

//
//Khoa ngoai KhachHang
//
        static public List<HoaDonDTO> LayDanhSachTheoMaKhachHang( int MaKhachHang)
        {
             Data.HoaDonRepository repo = new HoaDonRepository();
            return repo.LayDanhSachTheoMaKhachHang( MaKhachHang);
        }

        static public void XoaTheoMaKhachHang( int MaKhachHang, bool XoaKhoaNgoai=false)
        {
             Data.HoaDonRepository repo = new HoaDonRepository();
            repo.XoaTheoMaKhachHang( MaKhachHang,XoaKhoaNgoai);
        }

    }
}

